package DataTransfer;
import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

/**
 * @author alek
 *
 */
public class DefaultDataTransportConnector implements DataTransportConnector {
	private InterfaceDataTransporter mServer;
	private InterfaceDataTransporter mClient;
	
	public void setServer(InterfaceDataTransporter srv) 
	{
		mServer=srv;
	}
	
	public void setClient(InterfaceDataTransporter client) 
	{
		mClient=client;
	}
	
	public void connect() throws IOException
	{
		PipedInputStream srvPipIn=new PipedInputStream();
		PipedOutputStream srvPipOut=new PipedOutputStream();
		PipedInputStream cliPipIn=new PipedInputStream();
		PipedOutputStream cliPipOut=new PipedOutputStream();

		srvPipIn.connect(cliPipOut);
		cliPipIn.connect(srvPipOut);
		
		mServer.setInputStream(srvPipIn);
		mServer.setOutputStream(srvPipOut);
		
		mClient.setInputStream(cliPipIn);
		mClient.setOutputStream(cliPipOut);
	}

	public void disconnect()  throws IOException{
		mServer.close();
		mClient.close();
	}
}
